package com.cskaoyan.mall.dao;

import com.alibaba.druid.util.StringUtils;
import com.cskaoyan.mall.model.Order;
import com.cskaoyan.mall.model.OrderRequestParam;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @PackgeName: com.cskaoyan.mall.dao
 * @ClassName: OrderDaoImpl
 * @Author: admin
 * Date: 2020/5/5 21:00
 * project name: Javaproject1
 * @Version:
 * @Description:
 */
public class OrderDaoImpl implements OrderDao {
    @Override
    public Integer getTotal(OrderRequestParam param) {
        Map<String, Object> map = getDynamicSqlParams(param);
        return null;
    }

    private Map<String, Object> getDynamicSqlParams(OrderRequestParam param) {
        String baseSql = "select * from orders where 1 = 1 ";
        List<Object> sqlParams = new ArrayList<>();
        if (param.getState() != -1) {
            baseSql = baseSql + " and stateId = ?";
            sqlParams.add(param.getState());
        }
        if (!StringUtils.isEmpty(param.getMoneyLimit1())) {
            baseSql = baseSql + " and amount <= ?";
            sqlParams.add(Double.parseDouble(param.getMoneyLimit1()));
        }
        if (!StringUtils.isEmpty(param.getMoneyLimit2())) {
            baseSql = baseSql + " and amount >= ?";
            sqlParams.add(param.getGoods());
        }
        if (!StringUtils.isEmpty(param.getGoods())) {
            baseSql = baseSql + " and goods = ?";
            sqlParams.add(Double.parseDouble(param.getMoneyLimit2()));
        }
        if (!StringUtils.isEmpty(param.getAddress())) {
            baseSql = baseSql + " and amount >= ?";
            sqlParams.add(Double.parseDouble(param.getMoneyLimit2()));
        }
        if (!StringUtils.isEmpty(param.getName())) {
            baseSql = baseSql + " and amount >= ?";
            sqlParams.add(Double.parseDouble(param.getMoneyLimit2()));
        }
        if (!StringUtils.isEmpty(param.getId())) {
            baseSql = baseSql + " and amount >= ?";
            sqlParams.add(Double.parseDouble(param.getMoneyLimit2()));
        }
    }

    @Override
    public List<Order> orderByPage(OrderRequestParam param) {

        return null;
    }
}
